package com.syh.emissionservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.syh.emissionservice.pojo.CarbonDataWithDay;
import com.syh.emissionservice.pojo.CarbonDataWithMonth;
import com.syh.emissionservice.pojo.CarbonEmissions;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author syh
 * @since 2024-07-01
 */
@Mapper
public interface CarbonEmissionsMapper extends BaseMapper<CarbonEmissions> {
    @Select("SELECT DATE_FORMAT(emission_date, '%Y-%m') AS month," +
            " SUM(emission_amount) AS carbon " +
            "FROM carbon_emissions where company_id = #{companyId} " +
            "GROUP BY DATE_FORMAT(emission_date, '%Y-%m')" +
            " ORDER BY month;")
    List<CarbonDataWithMonth> getEcharts1(Integer companyId);

    @Select("SELECT emission_date AS day," +
            " SUM(emission_amount) AS carbon " +
            "FROM carbon_emissions where company_id = #{companyId} " +
            "GROUP BY emission_date" +
            " ORDER BY day;")
    List<CarbonDataWithDay> getEcharts2(Integer companyId);
    @Select("SELECT carbon_emissions.emission_amount FROM carbon_emissions where company_id = #{companyId}" +
            " ORDER BY created_at desc limit 0,2")
    List<BigDecimal> getTPrat(Integer companyId);
}
